package com.mryao.gxkygl.common.base.dao;

import com.mryao.gxkygl.common.base.entity.SysLog;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.mryao.gxkygl.common.base.dao.BaseRepository;

import java.util.Date;


public interface SysLogRepository extends BaseRepository<SysLog>{
	/**
	 * 通过用户的 url查询log对象
	 * @param operation
	 * @return
	 */
	
	@Query("select s from SysLog s where s.url = :operation and s.ip = :ip and s.username = :username")
	SysLog findSysLogByOperation(@Param("operation")String operation, @Param("ip")String ip,@Param("username")String username);
	
	/**
	 * 更新log对象
	 */
	@Transactional
	@Modifying
	@Query(value="update SysLog s set s.count = :count where s.url = :url")
	void updateSysLogByOperation(@Param("url") String operation,@Param("count") Integer count);

	/**
	 * 更新日志信息
	 * @param i
	 * @param createTime
	 * @param time
	 * @param value
	 * @param ipAddr
	 * @param username
	 */
	@Transactional
	@Modifying
	@Query(value="update SysLog s set s.count = :count,s.createTime = :createTime,s.time = :time where s.url = :url and s.ip = :ip and s.username = :username")
	void updateSysLogByOperation(@Param("count") int i,@Param("createTime") Date createTime, @Param("time") Integer time, @Param("url") String value, @Param("ip") String ipAddr, @Param("username")String username);
}
